/*
 * gsession-inhibit.h
 *
 *  Created on: Oct 29, 2010
 *      Author: Gordon Harris
 */

#ifndef GSESSIONINHIBIT_H_
#define GSESSIONINHIBIT_H_


#endif /* GSESSIONINHIBIT_H_ */

#define SM_DBUS_NAME		"org.gnome.SessionManager"
#define SM_DBUS_PATH		"/org/gnome/SessionManager"
#define SM_DBUS_INTERFACE	"org.gnome.SessionManager"


#define VERSION_MAX 16

#define APP_VERSION "20101122.1152"


#define APP_NAME			"session-inhibiter"
#define DEF_REASON			"not_idle"
#define DEF_DISPLAY			":0"
#define DEF_INHIBIT_TIME 	 60
#define NAME_MAX			255
#define COOKIE_MAX			 11		//4,294,967,295
#define DISPLAY_MAX			 11

//Options:

/* Figure out options and cmdline args
 *
 * NUMBER[SUFFIX]...
 *
 * -h --help
 * -v --version
 * -q --quiet
 * -d --debug
 * -s --save
 * -l --log [LOGFILE]
 * -r --reason [REASON]
 * -u --utc --gmt
 *
 */

//Types of inhibition:
/*
* 1: Inhibit logging out
* 2: Inhibit user switching
* 4: Inhibit suspending the session or computer
* 8: Inhibit the session being marked as idle
*/

//Types of inhibition..
#define NO_LOGOUT			0x00000001
#define NO_USERSWITCH		0x00000002
#define NO_SUSPEND			0x00000004
#define NO_IDLE				0x00000008


//Actions
#define ACT_ACTIONMASK		0x000000FF
#define ACT_INHIBIT			0x00000001
#define ACT_HELP			0x00000002
#define ACT_VERSION			0x00000004

//Options
#define OPT_OPTIONMASK		0x000FF000
#define OPT_QUIET			0x00001000
#define OPT_DEBUG			0x00002000
#define OPT_SAVE			0x00004000
#define OPT_LOG				0x00008000
#define OPT_UTC				0x00010000


#define uchar unsigned char


typedef struct {
	uint			 uOpts;								//Application Options
	GError     		*gError;							//dbus error message
	uchar			 uError;							//exit error code
	guint			 uInhibitFlags;						//Type of inhibition
	uint			 uInhibitCookie;					//Inhibit cookie passed from / to gnome session manager
	DBusGConnection *dBusConnection;					//dbus connection
	DBusGProxy      *dBusProxySessionManager;			//proxy to session manager
	float			fInhibitDuration;					//Fractional Inhibit duration..
	uchar			cInhibitUnits;						//InhibitDuration Units: s == seconds; m == minutes; h == hours; d == days
	uint			uInhibitSeconds;					//The actual number of seconds to inhibit...
	char			szAppVersion[VERSION_MAX];			//version number
	char			szAppName[NAME_MAX];				//Application name
	char			szAppPath[PATH_MAX];				//Application path
	char			szAppID[NAME_MAX];					//Application ID: AppName + UserName
	char			szAppReason[NAME_MAX];				//Reason for inhibiting..
	char			szAppDataFile[PATH_MAX];			//cookie file: ~/.appname
	char			szAppLogFile[PATH_MAX];				//Log file: default: /var/log/appname.log
	char			szAppDispEnv[DISPLAY_MAX];			//Env var for the display device..
}APPDATA, *LPAPPDATA;

//typedef LPAPPDATA * APPDATA;

//Return codes:

#define INHIBIT_SUCCESS			0
#define INHIBIT_ERROR			255


//Error Codes:

#define ERROR_NODBUS			100
#define ERROR_NOSESSION 		 99
#define ERROR_CANT_INHIBIT		 90
#define ERROR_CANT_UNINHIBIT	 80
#define ERROR_CANT_READDEFSECS	 70
#define ERROR_CANT_SAVEDEFSECS   60
#define ERROR_CANT_WRITELOG		 50

static gboolean PutDefInhibitSecs (LPAPPDATA lpAppData);
